﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Calibration.CApCalibrationCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Calibration.Resources;
using System;
using System.Windows;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.Calibration;

public class CApCalibrationCmd : TxButtonCommand
{
  private CApCalibrationEnabler _enabler;
  private TxWindow _calibrationWindow;

  public CApCalibrationCmd() => this._enabler = new CApCalibrationEnabler();

  public virtual bool Connect() => true;

  public virtual bool Licensed => TxCommandLicenser.CalibrationLicense;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this._enabler;

  public virtual string Bitmap => CalibrationResources.CALIBRATION_BITMAP;

  public virtual string Category => CalibrationResources.CALIBRATION_CATEGORY;

  public virtual string Description => CalibrationResources.CALIBRATION_DESCRIPTION;

  public virtual string Name => CalibrationResources.CALIBRATION_NAME;

  public virtual string Tooltip => CalibrationResources.CALIBRATION_TOOLTIP;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("Calibration");

  public virtual void Execute(object cmdParams)
  {
    if (!this._enabler.Enable || this._calibrationWindow != null)
      return;
    this._calibrationWindow = (TxWindow) new CUiCalibrationWindow();
    ((Window) this._calibrationWindow).Closed += new EventHandler(this._calibrationWindow_Closed);
    TxApplication.ApplicationEvents.Exiting += new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
    ((Window) this._calibrationWindow).Show();
  }

  private void _calibrationWindow_Closed(object sender, EventArgs e)
  {
    this._calibrationWindow = (TxWindow) null;
    TxApplication.ApplicationEvents.Exiting -= new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
  }

  private void ApplicationEvents_Exiting(object sender, TxApplication_ExitingEventArgs args)
  {
    if (this._calibrationWindow == null)
      return;
    ((Window) this._calibrationWindow).Close();
  }
}
